﻿using BotDetector.Core.Utilities;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace BotDetector.Core.NaiveBayesModule
{
    public class BayesTest :DetectorBaseModule
    {
        private BayesClassifier classifier;

        public BayesTest()
        {
            classifier = GetClassifier();
        }

        public bool HasClassifier()
        {
            if (classifier != null)
                return true;
            return false;
        }

        public double TestForBot(string text)
        {
            double rez = classifier.IsInClassProbability(Constants.BotLabel, text);
            return 1 - rez;
        }

        private BayesClassifier GetClassifier()
        {
            BayesFileOperator fileOperator = new BayesFileOperator();
            BayesClassifier classifier;

            try
            {
                classifier = fileOperator.ReadClassifier();
            }
            catch
            {
                classifier = null;
            }

            return classifier;
        }
    }
}
